import java.util.ArrayList;

import processing.core.*;


/**
 * @author Matt Sponnar
 * core.jar found at <insert link>
 */
public class Vision_app extends PApplet{
	
	static ArrayList<Mutant> data = new ArrayList<Mutant>();
	static ArrayList<GSquare> grid = new ArrayList<GSquare>();
	
	public void setup()	{
		
		size(1000, 801);
		background(0);
		smooth();

	}
	
	public void draw() {

		theGrid();
		melanopsin();
		lengend();

	}

	public static void main(String args[]) {
	    PApplet.main(new String[] { "--present", "Vision_app" });

	    // arraylist setup
		String inputFile = "resources/Melanopsin_Mutants.csv";
		CSVFile.readCSV(inputFile);
		CreateMutant.setData(CSVFile.getData());
		data = CreateMutant.getNewData();
	  }

	private void lengend() {
		
		GSquare mel = new GSquare(0,0,100,100,this);
		//Legend
		this.pushMatrix();
		this.translate(850, 100);
		this.fill(255, 255, 255);
		this.text("Mutations Key", 0, 0);
		
		this.pushMatrix();
		this.translate(0, 10);
		int[] color = mel.setColor(0);
		this.fill(color[0], color[1], color[2]);
		this.rect(0, 0, 10, 10);
		this.text("A388", 15, 10);
		this.popMatrix();
		
		this.pushMatrix();
		this.translate(0, 25);
		color = mel.setColor(1);
		this.fill(color[0], color[1], color[2]);
		this.rect(0, 0, 10, 10);
		this.text("A389", 15, 10);
		this.popMatrix();
		
		this.pushMatrix();
		this.translate(0, 40);
		color = mel.setColor(2);
		this.fill(color[0], color[1], color[2]);
		this.rect(0, 0, 10, 10);
		this.text("A391", 15, 10);
		this.popMatrix();
		
		this.pushMatrix();
		this.translate(0, 55);
		color = mel.setColor(3);
		this.fill(color[0], color[1], color[2]);
		this.rect(0, 0, 10, 10);
		this.text("A392", 15, 10);
		this.popMatrix();
		
		this.pushMatrix();
		this.translate(0, 70);
		color = mel.setColor(4);
		this.fill(color[0], color[1], color[2]);
		this.rect(0, 0, 10, 10);
		this.text("A394", 15, 10);
		this.popMatrix();
		
		this.pushMatrix();
		this.translate(0, 85);
		color = mel.setColor(5);
		this.fill(color[0], color[1], color[2]);
		this.rect(0, 0, 10, 10);
		this.text("A395", 15, 10);
		this.popMatrix();
		
		this.pushMatrix();
		this.translate(-25, 100);
		this.fill(255, 0, 0);
		this.text("Predictions are red", 0, 10);
		this.popMatrix();
		
		this.pushMatrix();
		int xoffset = -30;
		int yoffset = -20;
		int xmax = 149;
		int ymax = 120;
		this.line(0+xoffset, 0+yoffset, 0 + xmax, 0 + yoffset); //top
		this.line(0+xoffset, 0 + ymax, 0  + xmax, 0 + ymax); //bot
		this.line(0+xoffset, 0+yoffset, 0 + xoffset, 0 + ymax); //left
		this.line(0+xmax, 0+yoffset, 0 + xmax, 0 + ymax); //right
		this.popMatrix();
		
		this.popMatrix();
		
	}
	
	private void melanopsin() {
		this.pushMatrix();
		this.translate(850, 400);
		this.fill(255);
		this.text("Melanopsin", 5, 15);
		GSquare mel = new GSquare(0, 0, 100, 100, this);
		mel.getMine().setRadius(data.get(0).getData());
		mel.setup();
		mel.display(false, data.get(0).getMaxLocation());
		this.popMatrix();
		
	}
	
	private void theGrid() {
		
		int x = 0;  // counter for arraylist
		for(int i = 0; i < 800; i += 100){
			for(int j = 0; j < 800; j += 100){
				pushMatrix();
				translate(j, i);

				GSquare temp = new GSquare(0, 0, 100, 100, this);				
				// my code to test if I can get the arraylist in
				if(data.size() > ++x){
					
					temp.getMine().setRadius(data.get(x).getData());
					temp.setup();
					temp.display(data.get(x).isPrediction(), data.get(x).getMaxLocation());
					temp.displayMutations(data.get(x).getMutations());
					
				}
				else {
					temp.setup();
					temp.display(false, -1);
				}
				popMatrix();
			}
		}
	}
}
